#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import requests
import json

def test_api():
    print("🔍 测试API连接...")
    
    try:
        # 测试状态API
        response = requests.get("http://localhost:5002/api/status", timeout=5)
        print(f"状态API响应: {response.status_code}")
        if response.status_code == 200:
            data = response.json()
            print(f"状态: {data.get('status', 'unknown')}")
            print(f"消息: {data.get('message', 'unknown')}")
        
        # 测试城市API
        response = requests.get("http://localhost:5002/api/cities", timeout=5)
        print(f"城市API响应: {response.status_code}")
        if response.status_code == 200:
            data = response.json()
            cities = data.get('cities', [])
            print(f"城市数量: {len(cities)}")
            print(f"前5个城市: {cities[:5]}")
            if '东至' in cities:
                print("✅ 包含东至城市")
            else:
                print("❌ 不包含东至城市")
        
        print("✅ API测试完成")
        
    except Exception as e:
        print(f"❌ API测试失败: {e}")

if __name__ == '__main__':
    test_api()